package com.example.demonstrate.wang.utils;

import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;

/**
 * @Author along
 * @Date 2024/6/21 17:54
 */
public class BuildSearchQuery {

    /**
     * 构建查询请求
     * @param indexName
     * @param queryBuilder
     * @param from
     * @param size
     * @return 构建好的SearchRequest对象
     */
    public static SearchRequest buildSearchRequest(String indexName, BoolQueryBuilder queryBuilder, int from, int size) {
        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
        sourceBuilder.query(queryBuilder);
        sourceBuilder.from(from);
        sourceBuilder.size(size);
        SearchRequest searchRequest = new SearchRequest(indexName);
        searchRequest.source(sourceBuilder);
        return searchRequest;
    }
}
